/*******************************************************************************
 * 名称： 3152. 特殊数组 II
 * 地址： https://leetcode.cn/problems/special-array-ii/description/?envType=daily-question&envId=Invalid%20Date
 ******************************************************************************/

/**
 * @param {number[]} nums
 * @param {number[][]} queries
 * @return {boolean[]}
 */
var isArraySpecial = function (nums, queries) {
  const res = [];

  queries.forEach(([startIndex, endIndex]) => {
    let nextTypeIsSingle = null;
    let mineRes = true;

    for (let i = startIndex; i <= endIndex; i++) {
      let nowType = nums[i] % 2 === 1 ? true : false;

      // 第一个数据，直接跳过
      if (nextTypeIsSingle === null) {
        nextTypeIsSingle = !nowType;
        continue;
      }

      if (nextTypeIsSingle === nowType) {
        nextTypeIsSingle = !nowType;
      } else {
        mineRes = false;
        break;
      }
    }
    res.push(mineRes);
  });

  return res;
};

module.exports = {
  name: '3152. 特殊数组 II',
  testFc: isArraySpecial,
};
